<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <p>count: {{ count }}</p>
      <p>doubleCount: {{ doubleCount }}</p>
      <button v-on:click="count++">btn</button>

      <ul>
        <li v-for="item in oddList">{{ item }}</li>
      </ul>
      <button v-on:click="fn">btn2</button>
    </div>

    <script src="../Vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          count: 1,
          list: [1, 2, 3, 4, 5, 6, 7, 8],
        },
        // 计算属性, 需要有return
        // 本质是在不改变响应式数据的同时，去计算出或者过滤出想要的新数据,同时还具有响应式
        computed: {
          doubleCount() {
            return this.count * 2;
          },
          oddList() {
            return this.list.filter((item) => item % 2);
          },
        },
        methods: {
          fn() {
            this.list.push(9);
          },
        },
      });
    </script>
  </body>
</html>
